//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. 
//- <https://www.chatopera.com>, Licensed under the Chunsong Public 
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
//-
    原始 Freemarker 文件位置：https://gitlab.chatopera.com/chatopera/cskefu/blob/760e130e770a96a43e8f6f2c8a1eb0885c0bbf90/contact-center/app/src/main/resources/templates/apps/agent/calloutcontact/edit.html
    该页面项目中暂时没有使用，此处是没有完全转化的 Pug 文件
    如果提供这个页面，需要参考 Freemarker 原文件完成转化或参考实现

//  <#include "/public/macro.html">
html
    head
    body
        .uk-layui-form
            .box-header(style='background-color: #f5f5f5;')
                h1.site-h1(style='background-color:#FFFFFF;') 编辑联系人
            form.layui-form(action='/agent/calloutcontact/update.html', method='post')
                input(type='hidden', name='id', value='${contacts.id!\'\'}')
                input(type='hidden', name='shares', value='all')
                .layui-collapse
                    .layui-colla-item
                        h2.layui-colla-title 基本信息
                        .layui-colla-content.layui-show
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 获得时间：
                                    .layui-input-inline
                                        input#getdate.layui-input(type='text', name='touchtime', value='<#if contacts.touchtime??>${contacts.touchtime?string(\'yyyy-MM-dd\')}</#if>', readonly, lay-verify='date', autocomplete='off')
                                        i.layui-icon(style='position: absolute;right: 3px;top: 6px;font-size: 25px;') 
                                        span
                                            font(color='red') *
                                            b(style='font-size: 10px;') (您得到此联系人的时间)
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 类型：
                                    .layui-input-inline
                                        //                                 <#if contacts.ckind?? && contacts.ckind != ''>
                                        //                                 <@select "com.dic.contacts.ckind" "ckind" contacts.ckind!'' "lay-ignore required lay-verify='required' "/>
                                        //                                 <#else>
                                        //                                 <@select "com.dic.contacts.ckind" "ckind" "" "lay-ignore"/>
                                        //                             	</#if>
                                    span
                                        font(color='red') *
                    .layui-colla-item
                        h2.layui-colla-title 联系人信息
                        .layui-colla-content.layui-show
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label#cusname 联系人名称：
                                    .layui-input-inline
                                        input.layui-input(type='text', name='name', value='${contacts.name!\'\'}', required, lay-verify='required', autocomplete='off')
                                    span
                                        font(color='red') *
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 性别：
                                    .layui-input-inline
                                        .layui-input-block(style='width: 113%;')
                                            // 									<input type="radio" name="gender" value="1" title="男" <#if contacts?? && contacts.gender =='1'>checked</#if>>
                                            //       								<input type="radio" name="gender" value="0" title="女" <#if contacts?? && contacts.gender =='0'>checked</#if>>
                                            //       								<input type="radio" name="gender" value="-1" title="未知" <#if contacts?? && (contacts.gender !='1' && contacts.gender !='0')>checked</#if>>
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 生日：
                                    .layui-input-inline
                                        input#cusbirthday.layui-input(type='text', name='cusbirthday', value='${contacts.cusbirthday!\'\'}', autocomplete='off')
                                        i.layui-icon(style='position: absolute;right: 3px;top: 6px;font-size: 25px;') 
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 联系电话：
                                    .layui-input-inline
                                        input.layui-input(type='text', name='phone', lay-verify='entphone', value='${contacts.phone!\'\'}', autocomplete='off')
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 手机号：
                                    .layui-input-inline
                                        input#getdate.layui-input(type='text', name='mobileno', lay-verify='entphone', value='${contacts.mobileno!\'\'}', autocomplete='off')
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 城市：
                                    .layui-input-inline
                                        // 								<@select "com.dic.address.area" "province" contacts.province "lay-ignore"/>
                                .layui-inline
                                    .layui-input-inline#contacts_city
                                        // 								<@select contacts.city+".subdic" "city" contacts.city "lay-ignore"/>&lt;!&ndash; 二级字典，不存在的 CODE &ndash;&gt;
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 电子邮件：
                                    .layui-input-inline
                                        input.layui-input(type='text', name='email', lay-verify='entemail', value='${contacts.email!\'\'}', autocomplete='off')
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 联系人地址：
                                    .layui-input-inline
                                        input.layui-input(type='text', name='address', autocomplete='off', value='${contacts.address!\'\'}', style='width: 236%;')
                            .layui-form-item
                                .layui-inline
                                    label.layui-form-label 联系人说明：
                                    .layui-input-inline(style='width: 174%;')
                                        textarea.layui-textarea(name='memo', placeholder='请输入内容') ${contacts.memo!''}
                            .layui-form-button(style='position: inherit;')
                                .layui-button-block
                                    button.layui-btn(lay-submit, lay-filter='formDemo') 立即更新
                                    button.layui-btn.layui-btn-original(type='reset') 重置
            // 未选择标签style
            style.
                
                .unselectedClass {
                            display: inline-block;
                            font-weight: 400;
                            color: #000000;
                            text-align: center;
                            white-space: nowrap;
                            vertical-align: baseline;
                            border-radius: .25em;
                            background-color: #FFFFFF !important;
                            height: 22px;
                            line-height: 22px;
                            padding: 0 5px;
                            font-size: 14px;
                            border: solid 1px #CCCCCC;
                        }
                
            .box-body.ukefu-im-theme
                .uk-layui-form
                    .layui-collapse
                        .layui-colla-item
                            h2.layui-colla-title 标签
                            .layui-colla-content.layui-show
                                .layui-form-item
                                    .layui-inline
                                        label.layui-form-label(style='text-align: left;') 已有标签：
                                        #contactTags.layui-input-inline(style='width: 100%;').
                                            
                                            
            .box-body.ukefu-im-theme
                .uk-layui-form
                    .layui-collapse
                        .layui-colla-item
                            h2.layui-colla-title 笔记
                            .layui-colla-content.layui-show
                                .layui-form-item
                                    label.layui-form-label(style='text-align: left;') 笔记分类：
                                    .layui-input-inline
                                        select#notesCategory(name='notesCategory', lay-filter='category', required, lay-verify='required', style='display: inline')
                                            option(value='callout') 外呼
                                            option(value='callin') 呼入
                                            option(value='webim') 网页
                                .layui-form-item
                                    .layui-inline
                                        label.layui-form-label(style='text-align: left;') 内容：
                                        .layui-input-inline(style='width: 174%;')
                                            textarea#notesContent.layui-textarea(name='notes')
                                .layui-form-item
                                    .layui-button-inline(style='float: left;')
                                        button.layui-btn#notesAddBtn(lay-submit, lay-filter='notesbtn') 立即添加
        script.
            
            //Demo
                $('#province').change(function(){
                    loadURL('/res/dic.html?id='+$(this).val()+"&name=city&attr=lay-ignore&style=width:85px;display:inline-block;" , '#contacts_city');
                })
                layui.use('form', function() {
                    var form = layui.form();
                    form.render(); //更新全部
                    form.verify({
                        entphone: function(value){
                            if(value!="" && !new RegExp(/^1[3456789]\d{9}$/).test(value)){
                              return '请输入正确的电话号码';
                            }
                        },
                        entemail: function(value){
                            if(value!="" && !new RegExp(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/).test(value)){
                              return '请输入正确的电子邮箱地址';
                            }
                        }
                    });  
                });
                layui.use('element', function(){
                    var element = layui.element();
                });
                layui.use('laydate', function() {
                    var laydate = layui.laydate;
            
                    var date = {
                        min : '1950-01-01 00:00:00',
                        max : laydate.now(),
                        istoday : false
                    };
            
                    document.getElementById('getdate').onclick = function() {
                        date.elem = this;
                        laydate(date);
                    }
                    
                    document.getElementById('cusbirthday').onclick = function() {
                        date.elem = this;
                        laydate(date);
                    }
            
                });
            
